<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8"%>
<%@taglib prefix="mvc" uri="http://www.springframework.org/tags/form" %>
<%@taglib prefix="fmt" uri="http://www.springframework.org/tags" %>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>


<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <title>会议申请</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=10,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=0, minimum-scale=1.0, maximum-scale=1.0">
    <link rel="stylesheet" type="text/css" href="/lib/layui/layui/css/layui.css"/>
    <script type="text/javascript" src="/lib/layui/layui/layui.js"></script>
    <script type="text/javascript" src="/lib/layui/layui/layui.all.js"></script>
    <script type="text/javascript" src="/js/news/jquery-1.9.1.js"></script>
    <script type="text/javascript" src="/lib/jquery-2.1.4.min.js"></script>
    <script src="/js/base/base.js" type="text/javascript" charset="utf-8"></script>
    <script src="../js/webOffice/fileShow.js" type="text/javascript" charset="utf-8"></script>
    <style>
        .layui-anim-upbit {
            max-height: 200px !important;
        }
        .layui-form-label {
            width: 100px !important;
        }
        .layui-input-block {
            margin-left: 130px !important;
        }
        .textarea {
            float: left;
            cursor: pointer;
            resize:none;
            min-height: 38px;
            width: 350px;
        }
        .add {
            display: inline-block;
            padding: 2px 15px;
            font-weight: 400;
            line-height: 20px;
            text-align: center;
        }
        .table_box .layui-form-checkbox span{
            margin-left: 20px;
        }
        .download_a{
            color: blue;
        }
        .layui-anim-upbit{
            max-height: 250px !important;
        }
    </style>
</head>
<body>
<div class="layui-tab layui-tab-brief" lay-filter="docDemoTabBrief">
    <div class="headImg">
        <span style="font-size:22px;margin-left:10px;color:#494d59;margin-top: 2px"><img style="margin-left:1.5%" src="../img/commonTheme/theme6/icon_apply.png" alt=""><span style="margin-left: 10px">会议申请</span></span>
    </div>
    <hr>
    <div class="layui-tab-content">
        <div class="layui-tab-item layui-show">
            <div class="layui-form" >
                <div style="display: flex;margin-top: -10px;margin-left: 1.5%;margin-right: 1.5%;">
                    <div class="layui-form-item" style="width: 30%;margin-left: -82px">
                        <label class="layui-form-label" style="font-size: 14px">筛选</label>
                        <div class="layui-input-block">
                            <select name="city" lay-verify="required" class="search" lay-filter="searchSelect" >
                                <option value="">全部会议</option>
                                <option value="1">待审批会议</option>
                                <option value="2">已批准会议</option>
                                <option value="3">会议进行中</option>
                                <option value="4">未批准会议</option>
                                <option value="5">已结束会议</option>
                            </select>
                        </div>
                    </div>
                    <div style="margin-left: 58%"> <button type="button" class="layui-btn  huiyiDetail">会议使用情况</button></div>
                    <div style="margin-left: 3%"> <button type="button" class="layui-btn  btn_new">会议申请</button></div>
                </div>
                <div class="table_box" style="margin-left: 1.5%;margin-right: 1.5%;margin-top: -15px"><table id="internalTable" lay-filter="internalTable"></table></div>
            </div>
        </div>

    </div>
</div>

<script type="text/html" id="internalBar">
    <%--<a class="layui-btn layui-btn-xs" lay-event="edit">修改</a>--%>
    <%--<a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>--%>
    <%--<a class="layui-btn layui-btn-xs" lay-event="detail" >详情</a>--%>
    {{# if(d.meetStatus ==1){ }}
    <a class="layui-btn layui-btn-xs" lay-event="edit">修改</a>
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
    {{# } }}
    {{# if(d.meetStatus != 1){ }}
    <a class="" lay-event=""></a>
    {{# } }}

</script>


<!-- 会议申请-弹窗 -->
<div type="text/html" id="newModal" style="display: none;padding: 10px 40px 10px 0;">
    <form class="layui-form" lay-filter="newForm" id="addform">
        <div class="layui-form-item">
            <label class="layui-form-label">名称：<span style="color:red">*</span></label>
            <div class="layui-input-block">
                <input id="meetName" type="text" name="fromUnit" placeholder="请输入会议名称" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">主题：<span style="color:red">*</span></label>
            <div class="layui-input-block">
                <input id="subject" type="text" name="receiveUnit" placeholder="请输入会议主题" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">参会人员：<span style="color:red">*</span></label>
            <div class="layui-input-block">
                <textarea name="exchangeUserId" id="Senduser" style="min-height: 80px;" user_id=" "   lay-verify="required" placeholder="请选择参会人员" class=" textarea exchange_user" disabled></textarea>
                <a href="javascript:;" id="exchangeUserId" class="add" style="color: blue;">添加</a><br>
                <a href="javascript:;" id="clearSenduser" class="add" style="color: red;margin-top: 25px">清空</a>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">会议室：<span style="color:red">*</span></label>
            <div class="layui-input-block">
                <select id="meetRoomId" name="unitType" class="unit_type"  lay-filter="searchSelects">

                </select>
            </div>
        </div>
        <div class="layui-form-item ">
            <label class="layui-form-label">开始时间：<span style="color:red">*</span></label>
            <div class="layui-input-inline form-inline" >
              <input  type="text" class="layui-input  form-inline" id="beginTime" placeholder="" >
            </div>

        </div>
        <div class="layui-form-item ">
            <label class="layui-form-label">结束时间：<span style="color:red">*</span></label>
            <div class="layui-input-inline form-inline" >
              <input type="text" class="layui-input form-inline" id="endTime" placeholder="" >
            </div>

        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">审批人：<span style="color:red">*</span></label>
            <div class="layui-input-block">
                <select id="managerId" name="unitType" class="unit_type" lay-filter="aihao">

                </select>
            </div>
        </div>
        <div class="layui-form-item">
            <div style="display: inline">
            <span style="margin-left: 60px;">提前进入会议室时间<input id="advanceMin" type="text"  placeholder="" autocomplete="off" style="width: 40px;margin-left: 5px"></span>
            <%--<div class="layui-input-block ">--%>
              <%--<input id="meetTime" type="text"  placeholder="" autocomplete="off" class="layui-input" style="width: 40px">--%>
            <%--</div>--%>
            <span style="margin-left: 0px;margin-top: 0px">分钟</span>
            </div>
        </div>
        <div class="layui-form-item approver" >
            <label class="layui-form-label">通知审批人：</label>
            <div class="layui-input-block" >
                <input  id="smsRemind" type="checkbox"  name="smstype" value="1" title="发送事务提醒消息"  lay-skin="primary" checked>
                <input id="smsRemind1"  type="checkbox"  name="smstype" value="0" title="使用手机短信提醒" lay-skin="primary">
            </div>
        </div>
        <div class="layui-upload">
            <div id="demo2" style="padding-left: 110px;"></div>
            <label class="layui-form-label">附件：</label>
            <button type="button" class="layui-btn layui-btn-primary layui-btn layui-btn-sm" id="test3" style="border: 0px;color:#1E9FFF;padding: 0;"><img style="margin-right:5px;" src="/img/icon_uplod.png"><i class="layui-icon" style="display: none;"></i>附件上传</button>
        </div>
        <div class="layui-form-item ">
            <label class="layui-form-label">会议描述：</label>
            <div class="layui-input-block">
                <textarea placeholder="请输入内容" class="layui-textarea" id="meetDesc"></textarea>
            </div>

        </div>
    </form>
</div>

<script>

    $("#exchangeUserId").click(function(){//选人员控件
        user_id='Senduser';
        $.popWindow("../common/selectUser");
    });
    $('#clearSenduser').click(function(){
        $('#Senduser').get(0).setAttribute('user_id', '');
        $('#Senduser').val('');
    });

    layui.use(['form','table', 'layer', 'element', 'upload','laydate'], function(){
        var form = layui.form;
        var table = layui.table;
        var layer = layui.layer;
        var upload = layui.upload;
        var element = layui.element;
        var laydate = layui.laydate;
        form.render();
       //附件
        upload.render({
            elem: '#test3'
            ,url: '/upload?module=meeting' //上传接口
            ,accept: 'file' //普通文件
            ,done: function(res){
                layer.msg('上传成功');
                var data=res.obj[0];
                var fileExtension=data.attachName.substring(data.attachName.lastIndexOf(".")+1,data.attachName.length);//截取附件文件后缀
                var attName = encodeURI(data.attachName).replace(/\+/g, "%2b").replace(/\@/g,"%40").replace(/\#/g,"%23").replace(/\&/g,"%26").replace(/\//g,"%2F").replace(/\?/g,"%3F").replace(/\￥/g,"%ef%bf%a5").replace(/\$/g,"%24").replace(/\！/g,"%ef%bc%81").replace(/\（/g,"%ef%bc%88").replace(/\）/g,"%ef%bc%89").replace(/\…/g,"%e2%80%a6%e2%80%a6");
                var fileExtensionName=attName.substring(0,attName.lastIndexOf("."));
                var deUrl = data.attUrl.split('&ATTACHMENT_NAME=')[0]+"&ATTACHMENT_NAME="+fileExtensionName+"."+fileExtension+"&FILESIZE="+data.size;
                var str = '<div id="dechs" class="dech" style="padding: 3px 0;" deUrl="' + deUrl+ '"><a href="/download?'+encodeURI(deUrl)+'" NAME="' + data.attachName + '*"><img style="margin-top: -3px; margin-right: 3px;margin-left: 20px;" src="/img/attachment_icon.png"/>' + data.attachName + '</a><img class="deImgs" style="margin-left:5px;cursor: pointer;" src="/img/file/icon_deletecha_03.png"/><input type="hidden" data-attachname="'+data.attachName+'" class="inHidden" value="' + data.aid + '@' + data.ym + '_' + data.attachId + ',"></div>';

                $('#demo2').append(str);
            }
        });
        //删除附件
        $(document).on('click', '.deImgs',function(){
            var _this = this;
            var attUrl = $(this).parents('.dech').attr('deUrl');
            $.ajax({
                type: 'get',
                url: '/delete?'+attUrl,
                dataType: 'json',
                success:function(res){

                    if(res.flag == true){
                        layer.msg('删除成功', { icon:6});
                        $(_this).parent().remove();
                    }else{
                        layer.msg('删除失败', { icon:6});
                    }
                }
            })
        });
        // 初始化表格
        var internalTable = table.render({
            elem: '#internalTable'
            ,url: '/HSTmeeting/queryMeeting?useFlag=true'   //数据接口
            ,page: true //开启分页
            ,limit: 10
            ,cols: [[ //表头
                {field: 'meetName', align:'center',title: '会议名称',event: 'detailName', style:'cursor: pointer;color:blue'},
                {field: 'subject', align:'center',title: '会议主题'},
                {field: 'proposerTime', align:'center',title: '申请时间'},
                {field: 'startTime', align:'center',title: '开始时间'},
                {field: 'endTime',align:'center', title: '结束时间'},
                {field: 'roomName', align:'center',title: '会议室',event: 'detail', style:'cursor: pointer;color:blue'},
                {field: 'userIdName',align:'center', title: '申请人'},
                {field: 'meetStatus', title: '会议状态', align:'center', templet: function(d) {

                        if(d.meetStatus==1){ return '待审批'}
                        if(d.meetStatus==2){ return '已批准'}
                        if(d.meetStatus==3){ return '进行中'}
                        if(d.meetStatus==4){ return '未批准'}
                        if(d.meetStatus==5){ return '已结束'}

                    }},
                {title: '操作',align:'center', toolbar: '#internalBar',minWidth:150}
            ]]
            ,response: {
                statusName: 'flag',  //规定数据状态的字段名称，默认：code
                statusCode: true,   //规定成功的状态码，默认：0
                dataName: 'obj',    //规定数据列表的字段名称，默认：data
                countName: 'totleNum'
            }
        });
        //监听-内部公文交换设置-表格-工具条
        table.on('tool(internalTable)', function(obj){
            var tData = obj.data;
            var layEvent = obj.event;
            var hstRoomWithBLOBs=tData.hstRoomWithBLOBs
            console.log(tData)
            if(layEvent === 'edit'){
                $("#dechs").remove();

                layer.open({
                    type: 1,
                    title: '修改好视通视频会议申请',
                    content: $('#newModal'),
                    maxmin: true,
                    area: ['50%', '80%'],
                    btn: ['确认', '取消'],
                    success:function(){
                        $("#dechs").remove();

                        // $("#exchangeUserId").on("click",function(){//选人员控件
                        //     user_id='Senduser';
                        //     $.popWindow("../common/selectUser");
                        // });
                        // $('#clearSenduser').on("click", function(){
                        //     $('#Senduser').get(0).setAttribute('user_id', '');
                        //     $('#Senduser').val('');
                        // });
                        //回显
                        $.ajax({
                            url:'/HSTmeeting/selectMeetingId',
                            type:'get',
                            dataType:'json',
                            data:{
                                meetingId:tData.meetingId
                            },
                            success:function(obj){
                                var data=obj.obj1;
                                var strs='';
                                if(data.attachmentList.length>0){
                                    for(var i=0;i<data.attachmentList.length;i++){
                                        strs+='<div id="dechs" class="dech" deUrl="'+data.attachmentList[i].attUrl+'"><a href="<%=basePath %>download?'+data.attachmentList[i].attUrl+'" NAME="'+data.attachmentList[i].attachName+'*"><img style="width:16px;margin-left: 20px;" src="../img/file/cabinet@.png"/>'+data.attachmentList[i].attachName+'</a><img class="deImgs" style="margin-left:5px;cursor: pointer;" src="../img/file/icon_deletecha_03.png"/><input type="hidden" class="inHidden" value="'+data.attachmentList[i].aid+'@'+data.attachmentList[i].ym+'_'+data.attachmentList[i].attachId+',"></div>';
                                    }
                                }else{
                                    strs='';
                                }
                                $('#demo2').append(strs);
                                var userIds = data.userIds
                                $("#meetName").val(data.meetName);
                                $("#subject").val(data.subject);
                                $("#Senduser").val(data.userIdsName);
                                $('#Senduser').get(0).setAttribute('user_id', userIds);
                                $("#beginTime").val(data.startTime);
                                $("#endTime").val(data.endTime);
                                $("#meetDesc").val(data.meetDesc);
                                $("#advanceMin").val(data.advanceMin);


                                laydate.render({
                                    elem: '#beginTime'
                                    ,type: 'datetime'
                                    ,trigger:'click'
                                });

                                laydate.render({
                                    elem: '#endTime'
                                    ,type: 'datetime'
                                    ,trigger:'click'
                                    ,done: function(value, date, endDate){
                                        //判断会议室是否被占用
                                        $.get('/HSTmeeting/judgeMeeting',{
                                            roomId:$('#meetRoomId').val(),
                                            startTime:$('#beginTime').val(),
                                            endTime:value
                                        },function(res){
                                            if(res.code==1){
                                                $.layerMsg({content: res.msg, icon: 0})
                                                return false
                                            }
                                        })
                                    }
                                });

                                var roomId= data.roomId;
                                var managerId = data.managerId;
                                var str1="";
                                if(data.roomManagerNames.length>0){
                                    for(var i=0;i<data.roomManagerNames.length;i++){
                                        str1 += '<option value="' +data.roomManagerNames[i].userId + '," >' + data.roomManagerNames[i].userName + '</option>'                                    }

                                }else{
                                    sts1=''
                                }
                                console.log(managerId);
                                $("#managerId").html(str1);
                                $("#managerId option[value='"+managerId+"']").attr("selected","selected");//根据值让option选中




                                $.ajax({
                                    url: '/hstMeetingRoom/getAllMeetRoomAll',
                                    type: 'get',
                                    dataType: 'json',
                                    success: function (res) {
                                        var datas=res.obj;
                                        var str='';
                                        for(var i=0;i<datas.length;i++){
                                            str+='<option value="'+datas[i].roomId+'">'+datas[i].roomName+'</option>';

                                        }
                                        $("#meetRoomId").html(str);
                                        $("#meetRoomId option[value='"+roomId+"']").attr("selected","selected");//根据值让option选中

                                        form.render();

                                    }
                                });

                                form.on('select(searchSelects)', function(data){
                                    $.ajax({
                                        url: '/hstMeetingRoom/selectMeetRoomManager',
                                        type: 'get',
                                        dataType: 'json',
                                        data: {
                                            roomId:data.value,
                                        },
                                        success: function (res) {
                                            var data = res.obj1;
                                            var str3=''


                                            if(data.roomManagerNames.length>0){
                                                for(var i=0;i<data.roomManagerNames.length;i++){
                                                    str3 += '<option value="' +data.roomManagerNames[i].userId + '" >' + data.roomManagerNames[i].userName + '</option>'                                    }
                                            }else{
                                                sts3=''
                                            }
                                            $("#managerId").html(str3);
                                            form.render();
                                        }
                                    });
                                });


                            }
                        });

                    }
                    ,yes: function(index){
                        var attachmentId = '';
                        var attachmentName = '';
                        var $attachments = $('#demo2').find('input[type="hidden"]');
                        $attachments.each(function(){
                            attachmentId += $(this).val();
                            attachmentName += $(this).data('attachname') + ',';
                        });

                        var smsRemind=0;

                        if($('#smsRemind').is(':checked')){
                            smsRemind=1;
                        }
                        var smsRemindd=0;
                        if($('#smsRemind1').is(':checked')){
                            smsRemindd=1;
                        }

                        var paraData = {
                            meetingId:tData.meetingId,
                            meetName: $("#meetName").val(),
                            subject: $("#subject").val(),
                            startTime: $("#beginTime").val(),
                            endTime: $("#endTime").val(),
                            userIds:  $('#Senduser').get(0).getAttribute('user_id'),
                            smsRemind: smsRemind,
                            smsRemind2: smsRemindd,
                            meetDesc: $("#meetDesc").val(),
                            managerId: $("#managerId").val(),
                            RoomId: $("#meetRoomId").val(),
                            attachmentId:attachmentId,
                            attachmentName:attachmentName,
                            advanceMin:$("#advanceMin").val(),

                        }

                        var meetName = $("#meetName").val();
                        var subject = $("#subject").val();
                        var startTime = $("#beginTime").val();
                        var endTime = $("#endTime").val();
                        var userIds = $("#Senduser").val();

                        if(meetName=='' || subject=='' || startTime=='' || endTime=='' || userIds==''){
                            alert('带*号为必填项！')
                        }

                        if(meetName!='' && subject!='' && startTime!='' && endTime!='' && userIds!='' && endTime < startTime){
                            alert('会议结束时间必须大于开始时间！')
                        }

                        if(meetName!='' && subject!='' && startTime!='' && endTime!='' && userIds!='' && endTime > startTime){
                            $.ajax({
                                url: '/HSTmeeting/updateMeetingById',
                                type: 'post',
                                dataType: 'json',
                                data: paraData,
                                success: function (obj) {
                                    if (obj.flag) {
                                        $.layerMsg({content: '修改成功！', icon: 1}, function () {

                                        })
                                        internalTable.reload();
                                        layer.close(index);

                                    }else{
                                        alert('修改失败！');
                                    }
                                }
                            })
                            resetForm(form)
                        }






                    },
                    btn2: function(){
                        resetForm(form)

                    },
                    cancel: function(){
                        resetForm(form)

                    }
                })
            }
            else if(layEvent === 'del'){ //删除
                layer.confirm('确定删除该会议吗？', function(index){
                    obj.del();
                    layer.close(index);
                    $.post('/HSTmeeting/delMeetingById', {meetingId: tData.meetingId}, function(res){
                        if (res.flag) {
                            internalTable.reload({
                                url: '/HSTmeeting/queryMeeting?useFlag=true'
                                ,page: {
                                    curr: 1
                                }
                            });
                        }
                    })
                });
            }else if(layEvent === 'detailName'){
                $.ajax({
                    url:'/hstMeetingRoom/queryHstMeetingById',
                    type: "post",
                    dataType: "json",
                    data:{meetId:tData.meetingId},
                    success:function (res) {
                        var data=res.object
                        layer.open({
                            type: 1,
                            title: '会议详情',
                            shade: 0.5,
                            area: ['50%', '80%'],
                            content:'<form class="layui-form" id="ajaxforms" lay-filter="formsTest" style="width:90%;margin-left:5%;margin-top: 3%;">' +
                                '<table class="layui-table">\n' +
                                '  <tbody>\n' +
                                /*  '    <tr>\n' +
                                  '      <td nowrap="nowrap" style="width:20%">会议室名称:</td>\n' +
                                  '      <td class="roomName">' +data.roomName+
                                  '</td>\n' +
                                  '    </tr>\n' +*/
                                '    <tr>\n' +
                                '      <td nowrap="nowrap" style="width:20%">会议名称:</td>\n' +
                                '      <td class="meetName">'+data.meetName+'</td>\n' +
                                '    </tr>\n' +
                                '    <tr>\n' +
                                '      <td nowrap="nowrap">会议主题:</td>\n' +
                                '      <td class="subject">'+data.subject+'</td>\n' +
                                '    </tr>\n' +
                                '    <tr>\n' +
                                '      <td nowrap="nowrap">参会人员:</td>\n' +
                                '      <td class="userIdsName">'+data.userIdsName.substring(0,data.userIdsName.length-1)+'</td>\n' +
                                '    </tr>\n' +
                                '    <tr>\n' +
                                '      <td nowrap="nowrap">开始时间:</td>\n' +
                                '      <td class="startTime">'+data.startTime+'</td>\n' +
                                '    </tr>\n' +
                                '    <tr>\n' +
                                '      <td nowrap="nowrap">结束时间:</td>\n' +
                                '      <td class="endTime">'+data.endTime+'</td>\n' +
                                '    </tr>\n' +
                                '    <tr>\n' +
                                '      <td nowrap="nowrap">审批人:</td>\n' +
                                '      <td class="managerIdName">'+data.managerIdName.substring(0,data.managerIdName.length-1)+'</td>\n' +
                                '    </tr>\n' +
                                '    <tr>\n' +
                                '      <td nowrap="nowrap">提前进入会议室时间:</td>\n' +
                                '      <td class="advanceMin">'+function () {
                                    if(data.advanceMin==0){
                                        return  '按时进入会议'
                                    }else {
                                        return data.advanceMin+'分钟'
                                    }
                                }()+'</td>\n' +
                                '    </tr>\n' +
                                '    <tr>\n' +
                                '      <td nowrap="nowrap">附件:</td>\n' +
                                '      <td class="Table">'+function () {
                                    /* var arrAttach2 = res.object.attachmentList;
                                     var stra2 = '';
                                     if (arrAttach2 && arrAttach2.length > 0){
                                         for(var i=0;i<arrAttach2.length;i++){
                                             stra2+= '<div class="dech" style="max-width: 550px;" deUrl="' + encodeURI(arrAttach2[i].attUrl)+ '"><a title="'+ arrAttach2[i].attachName +'" style="display:inline-block;width:100%;overflow: hidden; word-break:break-all;white-space: nowrap;text-overflow: ellipsis;" href="<%=basePath %>download?'+encodeURI(arrAttach2[i].attUrl)+'" NAME="' + arrAttach2[i].attachName + '*"><img style="margin-right:10px;" src="../img/attachment_icon.png"/>' + arrAttach2[i].attachName + '</a></div>';
                                            }
                                        } else {
                                            stra2='无附件';
                                        }
                                        return stra2*/

                                }()+'</td>\n' +
                                '    </tr>\n' +
                                '    <tr>\n' +
                                '      <td nowrap="nowrap">会议描述:</td>\n' +
                                '      <td class="meetDesc">'+data.meetDesc+'</td>\n' +
                                '    </tr>\n' +
                                '  </tbody>\n' +
                                '</table>'+
                                '</form>',
                            success:function(){
                                var arr=res.object.attachmentList
                                attachmentShow_news(arr,$('.Table'));
                                for(var i=0;i<$('.font_').length;i++){
                                    $('.font_').eq(i).children(":first").remove()
                                }
                                $('.font_ .file_a  span').css('margin-left','12px')
                            }
                        })
                    }
                })
            }else if(layEvent === 'detail'){
                layer.open({
                    type: 1,
                    title: '会议室详情',
                    shade: 0.5,
                    area: ['40%', '53%'],
                    content:'<form class="layui-form" id="ajaxforms" lay-filter="formsTest" style="width:90%;margin-left:5%;margin-top: 3%;">' +
                        '<table class="layui-table">\n' +
                        '  <tbody>\n' +
                        '    <tr>\n' +
                        '      <td nowrap="nowrap" style="width:20%">会议室名称:</td>\n' +
                        '      <td class="meetName">'+hstRoomWithBLOBs.roomName+'</td>\n' +
                        '    </tr>\n' +
                        '    <tr>\n' +
                        '      <td nowrap="nowrap">会议室号:</td>\n' +
                        '      <td class="subject">'+hstRoomWithBLOBs.roomNo+'</td>\n' +
                        '    </tr>\n' +
                        '    <tr>\n' +
                        '      <td nowrap="nowrap">会议室密码:</td>\n' +
                        '      <td class="subject">'+hstRoomWithBLOBs.roomPwd+'</td>\n' +
                        '    </tr>\n' +
                        '    <tr>\n' +
                        '      <td nowrap="nowrap">服务器地址:</td>\n' +
                        '      <td class="subject">'+hstRoomWithBLOBs.serverAddr+'</td>\n' +
                        '    </tr>\n' +
                        '    <tr>\n' +
                        '      <td nowrap="nowrap">会议室管理员:</td>\n' +
                        '      <td class="userIdsName">'+hstRoomWithBLOBs.roomManagerName.substring(0,hstRoomWithBLOBs.roomManagerName.length-1)+'</td>\n' +
                        '    </tr>\n' +
                        '  </tbody>\n' +
                        '</table>'+
                        '</form>',
                })
            }
        });
        //筛选会议
        form.on('select(searchSelect)', function(data){
            $.get('/HSTmeeting/queryMeeting', function(res){
                if (res.flag) {
                    internalTable.reload({
                        where: {
                            meetStatus: data.value
                        }
                        ,page: {
                            curr: 1
                        }
                    });
                }
            });
        });
        // 新增-会议申请
        $('.btn_new').on('click', function(){
            $("#dechs").remove();
            layer.open({
                type: 1,
                title: '好视通视频会议申请',
                content: $('#newModal'),
                maxmin: true,
                area: ['50%', '80%'],
                btn: ['确认', '取消'],
                success:function(){

                    laydate.render({
                        elem: '#beginTime'
                        ,type: 'datetime'
                        ,trigger:'click'
                    });

                    laydate.render({
                        elem: '#endTime'
                        ,type: 'datetime'
                        ,trigger:'click'
                        ,done: function(value, date, endDate){
                            //判断会议室是否被占用
                            $.get('/HSTmeeting/judgeMeeting',{
                                roomId:$('#meetRoomId').val(),
                                startTime:$('#beginTime').val(),
                                endTime:value
                            },function(res){
                                if(res.code==1){
                                    $.layerMsg({content: res.msg, icon: 0})
                                    return false
                                }
                            })
                        }
                    });

                    $.ajax({
                        url: '/hstMeetingRoom/getAllMeetRoomAll',
                        type: 'get',
                        dataType: 'json',
                        success: function (res) {
                            var data=res.obj;
                            var str='';
                            var roomIds=data[0].roomId
                            for(var i=0;i<data.length;i++){
                                str+='<option value="'+data[i].roomId+'">'+data[i].roomName+'</option>';
                            }
                            $("#meetRoomId").append(str);
                            form.render();
                            $.ajax({
                                url: '/hstMeetingRoom/selectMeetRoomManager',
                                type: 'get',
                                dataType: 'json',
                                data: {
                                    roomId:roomIds,
                                },
                                success: function (res) {
                                    var data = res.obj1;
                                    var str2='';
                                    if(data.roomManagerNames.length>0){
                                        for(var i=0;i<data.roomManagerNames.length;i++){
                                            str2 += '<option value="' +data.roomManagerNames[i].userId + '" >' + data.roomManagerNames[i].userName + '</option>'                                    }
                                    }else{
                                        sts2=''
                                    }
                                    $("#managerId").html(str2);
                                    form.render();

                                }
                            });
                        }
                    });


                    form.on('select(searchSelects)', function(data){
                        $.ajax({
                            url: '/hstMeetingRoom/selectMeetRoomManager',
                            type: 'get',
                            dataType: 'json',
                            data: {
                                roomId:data.value,
                            },
                            success: function (res) {
                                var data = res.obj1;
                                var str2='';

                                if(data.roomManagerNames.length>0){
                                    for(var i=0;i<data.roomManagerNames.length;i++){
                                        str2 += '<option value="' +data.roomManagerNames[i].userId + '" >' + data.roomManagerNames[i].userName + '</option>'                                    }
                                }else{
                                    sts2='<option value="" selected></option>'
                                }
                                $("#managerId").html(str2);
                                form.render();

                            }
                        });
                    });
                    //是否有权限使用事务、短信提醒
                    $.ajax({
                        type:'get',
                        url:'/smsRemind/getRemindFlag',
                        dataType:'json',
                        data:{
                            type:73
                        },
                        success:function (res) {
                            if(res.flag){
                                if(res.obj.length>0){
                                    var data = res.obj[0];
                                    // 是否默事务提醒认发送
                                    if(data.isRemind=='0'){
                                        $('.smsRemind').prop("checked", false);
                                    }else if(data.isRemind=='1'){
                                        $('.smsRemind').prop("checked", true);
                                    }
                                    // 是否手机短信默认提醒
                                    if(data.isIphone=='0'){
                                        $('.smsRemind1').prop("checked", false);
                                    } else if (data.isIphone=='1'){
                                        $('.smsRemind1').prop("checked", true);
                                    }
                                    // 是否允许发送事务提醒
                                    if(data.isCan=='0'){
                                        $('.approver').hide();
                                        $('.smsRemind').prop("checked", false);
                                        $('.smsRemind1').prop("checked", false);

                                    }

                                }
                            }
                        }
                    })

                }
                ,yes: function(index){
                    var attachmentId = '';
                    var attachmentName = '';
                    var $attachments = $('#demo2').find('input[type="hidden"]');
                    $attachments.each(function(){
                        attachmentId += $(this).val();
                        attachmentName += $(this).data('attachname') + ',';
                    });


                    var smsRemind=0;
                    if($('#smsRemind').is(':checked')){
                        smsRemind=1;
                    }

                    var smsRemindd=0;
                    if($('#smsRemind1').is(':checked')){
                        smsRemindd=1;
                    }


                    var paraData = {

                        meetName: $("#meetName").val(),
                        subject: $("#subject").val(),
                        startTime: $("#beginTime").val(),
                        endTime: $("#endTime").val(),
                        userIds:  $('#Senduser').get(0).getAttribute('user_id'),
                        smsRemind: smsRemind,
                        smsRemind2: smsRemindd,
                        meetDesc: $("#meetDesc").val(),
                        managerId: $("#managerId").val()+',',
                        RoomId: $("#meetRoomId").val(),
                        attachmentId:attachmentId,
                        attachmentName:attachmentName,
                        advanceMin:$("#advanceMin").val(),

                    }

                    var meetName = $("#meetName").val();
                    var subject = $("#subject").val();
                    var startTime = $("#beginTime").val();
                    var endTime = $("#endTime").val();
                    var userIds = $("#Senduser").val();

                    if(meetName=='' || subject=='' || startTime=='' || endTime=='' || userIds==''){
                            alert('带*号为必填项！')
                    }

                    if(meetName!='' && subject!='' && startTime!='' && endTime!='' && userIds!='' && endTime < startTime){
                        alert('会议结束时间必须大于开始时间！')
                    }

                    if(meetName!='' && subject!='' && startTime!='' && endTime!='' && userIds!='' && endTime > startTime){
                        $.ajax({
                            url: '/HSTmeeting/insertMeeting',
                            type: 'post',
                            dataType: 'json',
                            data: paraData,
                            async: false,
                            success: function (obj) {
                                if (obj.flag) {
                                    $.layerMsg({content: '申请成功！', icon: 1}, function () {

                                    })
                                    internalTable.reload();
                                    layer.close(index);
                                    resetForm(form)
                                    window.location.reload()

                                }else{
                                    alert(obj.msg);

                                }
                            }
                        })
                    }




                },
                btn2: function(){
                    resetForm(form)

                },
                cancel: function(){
                    resetForm(form)

                }
            })
        });
        //会议使用情况
        $('.huiyiDetail').click(function () {
            layer.open({
                type: 2,
                title: '会议使用情况',
                area: ['100%', '100%'],
                maxmin:true,
                min: function(){
                    $('.layui-layer-shade').hide()
                },
                content:'/HSTmeeting/meetingDetails',
            })
        })
    });

    function resetForm(form) {
        $('#newModal').hide();
        $('.exchange_user').empty();
        $('#meetName').val('');
        $('#subject').val('');
        $('#beginTime').val('');
        $('#endTime').val('');
        $('#meetDesc').val('');
        $('#managerId').empty();
        $('#meetRoomId').empty();
        $('#Senduser').val('');
        $('#advanceMin').val('');
        $("#dechs").remove();
        $('#Senduser').get(0).setAttribute('user_id', "");
        $("#smsRemind1").prop("checked",false);

    }

    // 格式化时间 YYYY-MM-DD
    function formatDate(date) {
        var time = '';
        date = new Date(date);
        var month = date.getMonth() +1 < 10 ? '0'+(date.getMonth() +1) : date.getMonth() +1;
        var day = date.getDay() < 10 ? '0'+date.getDay() : date.getDate();
        var hour = date.getHours() < 10 ? '0' + date.getHours() : date.getHours();
        var minute = date.getMinutes() < 10 ? '0' + date.getMinutes() : date.getMinutes();
        var second = date.getSeconds() < 10 ? '0' + date.getSeconds() : date.getSeconds();
        time = date.getFullYear() + '-' + month + '-' + day + ' ' + hour + ':' + minute + ':' + second;
        return time;
    }


</script>
</body>
</html>